package com.jmx.yp.struts.role;

import java.util.*;
import net.sf.json.JSONObject;
import org.apache.log4j.*;
import com.jmx.yp.entity.GroupEmployee;
import com.jmx.yp.exception.ErrorCode;
import com.jmx.yp.service.group.IGroupinfoService;
import com.jmx.yp.service.role.IRoleService;
import com.opensymphony.xwork2.ActionContext;

/**
 * 
 * 功能描述：
 *			角色管理的业务控制
 * @author Jenny
 *
 * Date:2011-2-13 下午06:56:07
 */
public class RoleAction {
	private static Logger log = (Logger)Logger.getLogger(RoleAction.class);
	
	private IRoleService roleService;
	
	private IGroupinfoService groupService;
	
	public void setRoleService(IRoleService roleService){
		this.roleService = roleService;
	}
	
	public void setGroupService(IGroupinfoService groupService){
		this.groupService = groupService;
	}
	
	/**
	 * 查询角色列表-入口
	 * @return
	 */
	public String initQueryRole(){
		return "queryRole";
	}

	/**
	 * 根据条件查询角色信息
	 * 	  1、超级管理员
	 * 	  2、杰马逊管理员
	 *    3、组织机构管员
	 *    其中1、2两类管理员，允许创建及查询JMX级的角色，组织机构管理员只允许查询本机构的角色
	 * @return
	 */
	public String queryRole(){
		GroupEmployee user = (GroupEmployee)ActionContext.getContext().getSession().get("user");
		
		try{
			Long groupId = null;
			if(user.getGroup_srl() != null){
				boolean jmxFlag = groupService.isBlongToJMX(user.getGroup_srl());
				if(!jmxFlag)
					groupId = user.getGroup_srl();
			}
			Map map = roleService.getRoleList(groupId, queryRoleName, nowPage); 
			
			result = JSONObject.fromObject(map);
	System.out.println(result.toString());
		}catch(Exception e){
			e.printStackTrace();
			log.error("RoleAction queryRole error: " + e.getMessage());
			
		}
		return "success";
	}
	
	//属性值
	private String queryRoleName;
	private int nowPage;
	
	private JSONObject result;

	public void setNowPage(int nowPage){
		this.nowPage = nowPage;
	}
	
	public int getNowPage(){
		return nowPage;
	}
	
	public void setQueryRoleName(String queryRoleName){
		this.queryRoleName = queryRoleName;
	}
	
	public String getQueryRoleName(){
		return queryRoleName;
	}
	
	public void setResult(JSONObject result){
		this.result = result;
	}
	
	public JSONObject getResult(){
		return this.result;
	}
}
